﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using Jumbot.Common;
using JumbotCms.Common;
namespace JumbotCms.WebFile.User
{
    public partial class _changeavatarAjax : JumbotCms.API.UserCenter
    {
        private string _operType = string.Empty;
        private string _response = string.Empty;

        protected void Page_Load(object sender, EventArgs e)

        {
            if (!CheckFormUrl())
            {
                Response.Write("提交有误");
                Response.End();
            }

            this._operType = q("oper");
            switch (this._operType)
            {
                case "changeavatar":
                    ajaxChangeAvatar();
                    break;
                default:
                    DefaultResponse();
                    break;
            }
            Response.Write(this._response);
        }
        private void DefaultResponse()
        {
            User_Load("", "json");
        }
        private void ajaxChangeAvatar()
        {
            User_Load("", "json");
            if (Jumbot.Common.Session.Get("jcms_user_avatar").Length < 20)
            {
                this._response = JsonResult(0, "请重新上传原图");
                return;
            }
            string file = Jumbot.Common.Session.Get("jcms_user_avatar");
            int tow, toh, x, y, w, h;
            string info = q("info");
            string[] temp = info.Split(',');
            tow = Str2Int(temp[0]);
            toh = Str2Int(temp[1]);
            x = Str2Int(temp[2]);
            y = Str2Int(temp[3]);
            w = Str2Int(temp[4]);
            h = Str2Int(temp[5]);
            string DirectoryPath = site.Dir + "avatar";
            Jumbot.Common.DirFile.CreateDir(DirectoryPath);
            string thumbnailPath1 = Server.MapPath(DirectoryPath + "/" + UserId + "_l.jpg");
            string thumbnailPath2 = Server.MapPath(DirectoryPath + "/" + UserId + "_m.jpg");
            string thumbnailPath3 = Server.MapPath(DirectoryPath + "/" + UserId + "_s.jpg");
            Jumbot.Common.ImageHelp.MakeMyThumbPhoto(Server.MapPath(file), thumbnailPath1, tow, toh, x, y, w, h);
            Jumbot.Common.ImageHelp.MakeMyThumbPhoto(thumbnailPath1, thumbnailPath2, 48, 48, 0, 0, tow, toh);
            Jumbot.Common.ImageHelp.MakeMyThumbPhoto(thumbnailPath2, thumbnailPath3, 16, 16, 0, 0, 48, 48);
            Jumbot.Common.Session.Add("jcms_user_avatar", "");
            this._response = JsonResult(1, "形象制作成功");
        }
    }
}
